package load

import (
	"fmt"
	"time"
	"util"
)

/**
 * @Author：落叶知秋
 * @Date：16:14 2022/6/16
 * @note：
 **/

func (this *Loadmap) IsCollisions() {
	for _, g := range this.ghosts {
		if this.player.Col == g.Position.Col && this.player.Row == g.Position.Row {
			if g.Status == util.GhostStatusNormal {
				this.Lives--
				if this.Lives != 0 {
					//位置光标移动到此处
					moveCursor(this.player.Row, this.player.Col)
					fmt.Print(util.Cfg.Death) //死亡了，判定只要碰到就死了
					moveCursor(len(Maze)+2, 0)
					//更新，死了都重置了
					updateGhosts(this.ghosts, util.GhostStatusNormal)
					time.Sleep(200 * time.Millisecond)
					//复原位置
					this.player.Row, this.player.Col = this.player.StartRow, this.player.StartCol
				}
			} else if g.Status == util.GhostStatusBlue {
				updateGhosts([]*util.Ghost{g}, util.GhostStatusNormal)
				g.Position.Row, g.Position.Col = g.Position.StartRow, g.Position.StartCol
			}

		}
	}
}
func (this *Loadmap) IsLose() bool {
	if this.NumDots == 0 || this.Lives == 0 {
		if this.Lives == 0 {
			moveCursor(this.player.Row, this.player.Col)
			fmt.Println(util.Cfg.Death)
			moveCursor(this.player.StartRow, this.player.StartCol)
			fmt.Println("Game Over!")
			moveCursor(len(Maze)+2, 0)
			return true
		}
		return true
	}
	return false
}
func (this *Loadmap) IsWin() bool {
	if this.Score == 100 || this.Num_Pill == 4 {
		moveCursor(this.player.Row, this.player.Col)
		fmt.Println(util.Cfg.Win)
		moveCursor(this.player.StartRow, this.player.StartCol)
		fmt.Println("game victory!")
		moveCursor(len(Maze)+2, 0)
		return true
	}
	return false
}
